]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - Super Polarity/Actors/Actor.cs
Merge branch 'master' of github.com:benbeltran/super-polarity
[rbdr/super-polarity] / Super Polarity / Actors / Actor.cs
index 8c71af080a9c677bb720941d6d7a08af6ba551ba..3bb06beeedcae39694d87fb4f1e78357dddd9b9e 100644 (file)
@@ -19,7 +19,7 @@ namespace SuperPolarity
         protected Vector2 Origin;
         public bool Active;
         public Rectangle Box;
-        protected Vector4 BoxDimensions;
+        public Vector4 BoxDimensions;
         protected Texture2D BoxTexture;
 
         // Physical Properties
@@ -29,9 +29,9 @@ namespace SuperPolarity
         public float Angle;
 
         // Constraints / Behavior
-        protected float MaxVelocity;
+        public float MaxVelocity;
         protected float AccelerationRate;
-        protected int HP;
+        public int HP;
         protected bool Immortal;
         public bool Dying;
         public int Value;
@@ -52,6 +52,10 @@ namespace SuperPolarity
         public Actor(SuperPolarity newGame)
         {
             game = newGame;
+            BoxDimensions.X = 20;
+            BoxDimensions.Y = 20;
+            BoxDimensions.W = 15;
+            BoxDimensions.Z = 15;
         }
 
         public virtual void Initialize(Texture2D texture, Vector2 position)
@@ -71,10 +75,6 @@ namespace SuperPolarity
 
             HP = 1;
             Immortal = false;
-            BoxDimensions.X = 20;
-            BoxDimensions.Y = 20;
-            BoxDimensions.W = 20;
-            BoxDimensions.Z = 20;
 
             Dying = false;
             Value = 1;
@@ -88,7 +88,7 @@ namespace SuperPolarity
 
         protected void InitBox()
         {
-            Box = new Rectangle((int)(Position.X - BoxDimensions.X), (int)(Position.Y - BoxDimensions.X), (int)(BoxDimensions.X + BoxDimensions.W), (int)(BoxDimensions.Y + BoxDimensions.Z));
+            Box = new Rectangle((int)(Position.X - BoxDimensions.X), (int)(Position.Y - BoxDimensions.X), (int)(BoxDimensions.X + BoxDimensions.X + BoxDimensions.W), (int)(BoxDimensions.Y + BoxDimensions.Y + BoxDimensions.Z));
         }
 
         public void AutoDeccelerate(GameTime gameTime)
@@ -195,18 +195,30 @@ namespace SuperPolarity
 
         public void ChangeAngle()
         {
+            if (Math.Abs(Velocity.Y) <= 0.1 && Math.Abs(Velocity.X) <= 0.1)
+            {
+                return;
+            }
             Angle = (float)Math.Atan2(Velocity.Y, Velocity.X);
         }
 
         public virtual void Draw(SpriteBatch spriteBatch)
         {
-            foreach (Actor child in Children)
+            Actor child = null;
+            
+            //  TODO: Check what's up with the null children.
+            if (Children == null)
             {
+                return;
+            }
+            for (var i = Children.Count - 1; i >= 0; i--)
+            {
+                child = Children[i];
                 child.Draw(spriteBatch);
             }
 
             spriteBatch.Draw(Texture, Position, null, Color, Angle, Origin, 1f, SpriteEffects.None, 0f);
-            spriteBatch.Draw(BoxTexture, Box, new Color(255, 0, 255, 25));
+            //spriteBatch.Draw(BoxTexture, Box, new Color(255, 0, 255, 25));
         }
 
         void CheckOutliers()
@@ -243,5 +255,13 @@ namespace SuperPolarity
         {
             Dying = true;
         }
+
+        public virtual void CleanUp()
+        {
+            Texture = null;
+            BoxTexture = null;
+            Children = null;
+            Texture = null;
+        }
     }
 }